#include<bits/stdc++.h>
using namespace std;
const int N=1e7+5,mod=1e9+7;
long long sum[N],a[15],t,n;
int pd(long long i)
{
	int ans=0;
	while(i)
	{
		++a[i%10];
		i/=10;
	}
	for(int j=1;j<=9;++j)
	{
		if(a[ans]<=a[j])
			ans=j;
	}
	for(int j=0;j<=9;++j)
		a[j]=0;
	return ans;
}
int main()
{
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=1;i<=N-5;++i)
		sum[i]=sum[i-1]+pd(i)%mod;
	cin>>t;
	while(t--)
	{
		cin>>n;
		cout<<sum[n]<<'\n';
	}
	return 0;
 } 
